
let CONFIG=require('../config');
export function getData (url,data,loading={show:true,title:'加载中',mask:false}) {
  var url=CONFIG.domain+url
  let promise=new Promise((resolve ,reject) => {
    if(loading.show){
      wx.showLoading({title: loading.title,mask:loading.mask})
    }
    wx.request({
      url:url,
      data:data,
      method:"GET",
      header:{
        "content-type":"application/json"
      },
      success:res =>{
        
        resolve(res)
        if(loading.show){
          wx.hideLoading()
        }
      },
      fail:err =>{
        reject(err)
        if(loading.show){
          wx.hideLoading()
        }
      }
    })
  })
  return promise;
};
export function postData (url,data,loading={show:true,title:'加载中',mask:false}) {
  var url=CONFIG.domain+url
  let promise=new Promise((resolve ,reject) => {
    if(loading.show){
      wx.showLoading({title: loading.title,mask:loading.mask})
    }
    wx.request({
      url:url,
      data:data,
      method:"POST",
      header:{
        "content-type":"application/json"
      },
      success:res =>{
       
        resolve(res)
        wx.hideLoading()
      },
      fail:err =>{
        reject(err)
        wx.hideLoading()
      }
    })
  })
  return promise;
}

export default {
  getData,
  postData
}
